using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
using Warlock.Input;


namespace Warlock
{
    public class MapLoad : IGameScreen
    {
        Texture2D Lavat;
        Texture2D Groundt;
        SpriteBatch Lava;
        SpriteBatch Ground;
        int x = 0;
        int y = 0;
        float scale = 1f;
        float keytimer;
        float keytimers;

        public Game1 MainGame { get; set; }

        /// <summary>
        /// Der Konstruktor...
        /// </summary>
        /// <param name="game">Das Haupt-Game Objekt</param>
        /// <param name="Lavatext">Der Pfad zu der Lava-Textur</param>
        /// <param name="Groundtext">Der Pfad zu der Boden-Textur</param>
        /// <param name="Meltspeed">Die Geschwindigkeit, mit der sich das Feld verkleinert</param>
        public MapLoad(Game1 game, String Lavatext, String Groundtext, float Meltspeed)
        {
            InputManager.Instance.KeyDown += new KeyDownEventHandler(Instance_KeyDown);
            MainGame = game;
        }

        void Instance_KeyDown(KeyPressedEventArgs e)
        {
            if (e.Key == Keys.Escape)
                MainGame.Exit();
        }

        public void Initialize(GraphicsDeviceManager graphics, ContentManager content)
        {
            Lavat = content.Load<Texture2D>("Resources\\Ground\\UnterGrund");
            Groundt = content.Load<Texture2D>("Resources\\Ground\\Grund");
            Lava = new SpriteBatch(graphics.GraphicsDevice);
            Ground = new SpriteBatch(graphics.GraphicsDevice);
            keytimers = 4 * 1000;
            keytimer = 4 * 1000;
        }

        public void UnloadContent()
        {
            //Input wieder deregistrieren
            InputManager.Instance.KeyDown -= Instance_KeyDown;
        }

        public void Update(GameTime gameTime)
        {
        }

        public void Draw(SpriteBatch spriteBatch, GameTime gameTime)
        {
            Lava.Begin(SpriteBlendMode.AlphaBlend);
            Lava.Draw(Lavat, Vector2.Zero, Color.White);
            Lava.End();
            Ground.Begin(SpriteBlendMode.AlphaBlend);
            Ground.Draw(Groundt, new Vector2(x, y), new Rectangle(0, 0, 800, 800), Color.White, 0f, new Vector2(0, 0), scale, SpriteEffects.None, 0);
            Ground.End();
            if (keytimer <= 0.0f)
            {
                scale -= 0.01f;
                y += 4;
                x += 4;
                keytimer = keytimers;
            }
            keytimer -= gameTime.ElapsedGameTime.Milliseconds;
        }
    }
}